export const preLoadImg = dir => {
	const pr = []
	const images = {}
	const requireComponent = require.context(
		'../static',
		true,
		/\.(gif|png|jpg)$/
	)
	
	requireComponent.keys().forEach(fileName => {
		const url = requireComponent(fileName)
		const name = fileName.replace(/^\.\/(.*)\.\w+$/, '$1')
		let p = loadImage(url)
			.then(img => {
				
				})
			.catch(err => console.log(err))
		pr.push(p)
		images[name] = url
	})
	Promise.all(pr)
	return images
}

const loadImage = url => {
	return new Promise((resolve, reject) => {
		let img = new Image()
		img.onload = () => {
			resolve(img)
		}
		img.onerror = reject
		img.src = url
	})
}





